﻿using System;
using System.Linq;
using System.Web.UI.HtmlControls;

public partial class Components_CategorySelector : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AddCssLink();
    }

    private void AddCssLink()
    {
        var controls = Page.Header.Controls.OfType<HtmlLink>().ToArray();

        string href = ResolveUrl("~/Styles/CategorySelector.css");
        for (int i = 0; i < controls.Length; i++)
        {
            if (controls[i].Href == href)
                return;
        }

        var link = new HtmlLink { Href = href };
        link.Attributes.Add("rel", "stylesheet");
        link.Attributes.Add("type", "text/css");
        Page.Header.Controls.Add(link);
    }
}